// page/member/indent.js
var app = getApp()
Page({
  data: {
    /** 
        * 页面配置 
        */
    winWidth: 0,
    winHeight: 0,
    // tab切换  
    currentTab: 0,
    index: 0,
    selected: true,
    selected1: false,
    payStatus:1,
    type: 0
  },
  onLoad: function () {
    var that = this
    that.setData({
      isHide: true,
      // options: options
    })
    /** 
     * 获取系统信息 
     */
    wx.getSystemInfo({

      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight
        });
      }

    });
  },
  /** 
     * 滑动切换tab 
     */
  bindChange: function (e) {
    var that = this;
    that.setData({ currentTab: e.detail.current });
  },
  /** 
   * 点击tab切换 
   */
  swichNav: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },
  /** 
   * 滑动切换tab 
   */
  bindChanges: function (e) {
    var that = this;
    that.setData({ currentTab: e.detail.current });
  },
  /** 
   * 点击tab切换 
   */
  swichNavs: function (e) {
    var that = this;
    if (this.data.currentTabs === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTabs: e.target.dataset.current,

      })
    }
  },
  selected: function (e) {
    this.setData({
      selected1: false,
      selected: true,
      type: 0
    })
    this.getlist();
    console.log(e.target.dataset.type)
  },
  selected1: function (e) {
    this.setData({
      selected: false,
      selected1: true,
      type: 1
    })
    this.getlist();
    console.log(e.target.dataset.type)
  },
  onShow: function () {
    this.getlist();
  },
  getlist: function () {
    var app = getApp()
    var that = this;
    var uid = wx.getStorageSync('uid');
    var type = that.data.type

    wx.request({
      url: app.globalData.host + '&g=App&m=User&a=my_order',
      data: {
        uid: uid,
        type: that.data.type
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res.data)
        var list = res.data.list;
        that.setData({
          list: res.data.list,
        })
      }
    })
    that.setData({
      isHide: 1,
    })
  },
  conPay: function (e) {
    var app = getApp();
    var oid = e.target.dataset.oid
    //console.log(e.target.dataset)    
    //return false;
    if (this.data.payStatus == 1) {
      this.setData({
        payStatus: 0,
      })
      wx.request({
        url: app.globalData.host + '&g=App&m=Order&a=wx_p1',
        data: { oid: oid },
        header: {
          'content-type': 'application/json'
        },
        success: function (res) {         
          //console.log(res)
          wx.requestPayment({
            'appId': res.data.appId,
            'timeStamp': res.data.timeStamp,
            'nonceStr': res.data.nonceStr,
            'package': res.data.package,
            'signType': 'MD5',
            'paySign': res.data.paySign,
            'success': function (res) {
              console.log('success');
              wx.showToast({
                title: '支付成功',
                icon: 'success',
                duration: 2000
              })     
              this.getlist();         
            },
            'fail': function (res) {
              console.log(res);
              console.log('fail');
            },
            'complete': function (res) {
              console.log(res);
              console.log('complete');
            }
          })
        }
      })
    }

  },
  // 删除
  delItem: function (e) {
    var app = getApp();
    var oid = e.target.dataset.id    
    wx.request({
      url: app.globalData.host + '&g=App&m=User&a=cancleOrder',
      data: { oid: oid },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        this.getlist();  
        //   console.log(that.data.imgUrls)
      }
    })
    
  },
})